package mediadisplay.timeline.controls 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	/**
	 * ...
	 * @author Anders Figenschow selvfølgelig
	 */
	public class TickBox extends Sprite
	{
		private var _txt:String;
		public var ticked:Boolean = false;
		private static const SIZE:int = 16;
		
		public function TickBox(txt:String) 
		{
			_txt = txt;
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			
			graphics.clear();
			graphics.lineStyle(1, 0);
			graphics.beginFill(0xffffff);
			graphics.drawRect(0, 0, SIZE, SIZE);
			graphics.endFill();
			
			buttonMode = true;
			
			//alpha = 0.5;
			
			addEventListener(MouseEvent.CLICK, toggle);
			addEventListener(Event.REMOVED_FROM_STAGE, cleanup);
		}
		
		private function cleanup(e:Event):void 
		{
			removeEventListener(Event.REMOVED_FROM_STAGE, cleanup);
			removeEventListener(MouseEvent.CLICK, toggle);
			
		}
		
		public function setTick(ticked:Boolean = false):void {
			if (ticked) drawTicked();
			else drawUnTicked();
			this.ticked = ticked;
		}
		
		public function getTicked():Boolean {
			return this.ticked;
		}
		
		public function toggle(e:MouseEvent):void 
		{
			//if (alpha == 0.5) return;
			
			ticked = !ticked;
			
			if (ticked) {
				drawTicked();
			} else {
				drawUnTicked();
			}
			
			
		}
		
		private function drawUnTicked():void 
		{
				graphics.clear();
				graphics.lineStyle(1, 0);
				graphics.beginFill(0xffffff);
				graphics.drawRect(0, 0, SIZE, SIZE);
				graphics.endFill();				
			
		}
		
		private function drawTicked():void 
		{
				graphics.clear();
				graphics.lineStyle(1, 0);
				graphics.beginFill(0xffffff);
				graphics.drawRect(0, 0, SIZE, SIZE);
				graphics.endFill();
				graphics.moveTo(0, 0);
				graphics.lineTo(SIZE, SIZE);
				graphics.moveTo(0, SIZE);
				graphics.lineTo(SIZE, 0);
			
		}
		
		
	}

}